from flask import Flask,Blueprint
from flask.ctx import AppContext
from flask_socketio import SocketIO, emit
from flask_sqlalchemy import SQLAlchemy
import config
from flask_wtf import CSRFProtect
from flask_restful import Api
from flask_cors import CORS
from flask_mail import Mail
from redis import Redis

def create_app(db):
    app = Flask(__name__, static_folder='./static')

    with AppContext(app):
        app.config.from_object(config)
        db.init_app(app)
        CORS(app=app,supports_credentials=True)
        return app


db = SQLAlchemy()
app = create_app(db)
mail = Mail(app=app)
redis = Redis(db=2)
csrf = CSRFProtect(app=app)
api = Api(app=app)
socket_io = SocketIO()
socket_io.init_app(app)
